fix/snapshot: prevent OS command injection via targets file#1351
Merged
cbrnrd merged 3 commits intoJul 8, 2026
Merged
Conversation
andreeleuterio
approved these changes
Jul 7, 2026
andreeleuterio
left a comment
Member
There was a problem hiding this comment.
let's get some eyes from @jac (or someone he points to)
jac
approved these changes
Jul 7, 2026
jac
left a comment
Member
There was a problem hiding this comment.
I haven't looked at this in years but it looks good to me 👍🏻
…ows-os-command-injection-via-malicious
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
src snapshot databases/restore --runbuilt shell command strings by interpolating untrusted YAML fields (target, dbname, username, password) and executed them viaexec.Command("bash", "-c", c), allowing shell-metacharacter injection. This could allow a malicious YAML author to run commands on a user's machine.Solution
Don't use
bash -canymore!Reworked
internal/pgdump/pgdump.goto build commands as argv arrays instead of shell strings:Commandstruct (Env, Args, InputFile, OutputFile) with aRun()that executes directly viaexec.Command(args[0], args[1:]...)and does file redirection in Go (ie nobash -c).DumpCommand/RestoreCommandnow return(args, env []string), so each untrusted value is a discrete argv element (e.g.--host=<target>,--dbname=<value>,PGPASSWORDin env).sh -c/bash -cinner command is safely shell-quoted (shellQuote/shellQuoteEnv), preventing injection even inside the container.Test plan
CI, net-new unit tests